package com.xiaowu.datajpa.api;

import com.xiaowu.datajpa.entity.Teacher;
import com.xiaowu.datajpa.service.TeacherSercvice;
import com.xiaowu.datajpa.service.TeacherSercvice;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "教师管理")
@RestController
@RequestMapping("/api/teacher")
public class TeacherApiController {
    @Autowired
    private TeacherSercvice teacherService;
    @GetMapping("/list")
    public List<Teacher> getList(){
        List<Teacher> teachers = teacherService.findAll();
        return teachers;
    }

    @GetMapping("/search")
    public List<Teacher> findByNameLike(@Param("name") String name){
    	List<Teacher> teachers = teacherService.findByNameLike(name+"%");
    	return teachers;
    }

    @GetMapping("/{id}")
    public Teacher findById(@PathVariable Integer id) {
        return teacherService.findById(id);
    }
    @PostMapping("/add")
    public Teacher add(Teacher teacher) {
    	return teacherService.insert(teacher);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable Integer id) {
    	teacherService.delete(id);
    }

    @PutMapping("/update")
    public Teacher update(Teacher teacher) {
    	return teacherService.update(teacher);
    }
}
